
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using CommandBuilder;
using Common;

namespace AndroidLinkClient
{
    [Activity(Label = "Mouse")]
    public class Mouse : Activity
    {
		float currentX, currentY;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Create your application here
            SetContentView(Resource.Layout.Mouse);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public override bool OnTouchEvent(MotionEvent e)
        {
            Command c = new Command();
            switch (e.Action)
            {
                case MotionEventActions.Down:
                    c.Type = "mouse";
                    c.Operation = "down";
                    c.Commands.Clear();
                    Work._default.Send(Creator.CreateXml(c));
                    break;
                case MotionEventActions.Move:
                    c.Type = "mouse";
                    c.Operation = "move";
                    c.Commands.Clear();
                    float x = e.GetX();
                    float y = e.GetY();
                    float deltaX = x - currentX;
                    float deltaY = y - currentY;
                    c.Commands.Add(new CommandItem() { Name = "x", Value = deltaX.ToString() });
                    c.Commands.Add(new CommandItem() { Name = "y", Value = deltaY.ToString() });
                    Work._default.Send(Creator.CreateXml(c));
                    currentX = x;
                    currentY = y;
                    break;
                case MotionEventActions.Up:
                    c.Type = "mouse";
                    c.Operation = "up";
                    c.Commands.Clear();
                    Work._default.Send(Creator.CreateXml(c));
                    break;
                default:
                    break;
            }
            return base.OnTouchEvent(e);
        }
    }
}

